package org.NooLab.glue.msgframe;


import java.io.Serializable;
import java.util.Observer;
import java.util.Vector;

import org.NooLab.glue.components.DataConnector;
import org.NooLab.glue.components.MessageBoardFactory;
import org.NooLab.glue.components.MessageBoardFactoryProperties;
import org.NooLab.glue.components.pkg.TaskPackage;

import org.NooLab.glue.interfaces.ReceptorDigestIntf;
import org.NooLab.glue.subscription.FilterPackageIntf;
import org.NooLab.glue.transaction.Transaction;
import org.NooLab.utilities.logging.PrintLog;

// http://stackoverflow.com/questions/5189690/how-to-serialize-and-de-serialize-objects-using-jaxb


/**
 * 
 * <p>as part of the registration, the registering participant may provide a collection of
 * features and their values, upon which a similarity reasoning for client-matching could be performed;<br/>
 * it (probably??) also may provide a table which represents a SOM for client-matching, where the 
 * size of the feature vector is limited to around 20 positions and the size of the map to at most 200 nodes;<br/>
 * </p>
 * this associative client matching introduces a random element in client-matching
 * 
 * a further format could be boolean table (rows:OR, cols:AND) for providing more complex rules of matching  
 *
 */
public class XRegistration implements Serializable, Cloneable {
	
	transient private static final long serialVersionUID = 8396234602313026920L;
	
	// =================================
	
	transient public static int RST_IS_TIMEDOUT   = -95;
	transient public static int RST_CTYPEUNDEF    = -7;
	transient public static int RST_CTYPENOMATCH  = -6;
	
	transient public static int RST_IS_NOREGIST   = -1;
	
	transient public static int RST_IS_STARTED    = 0;
	transient public static int RST_IS_CNXCONF    = 1;
	transient public static int RST_IS_IDLE       = 8;
	transient public static int RST_IS_AVAIL      = 10;
	transient public static int RST_IS_RECOGNIZED = 15;
	transient public static int RST_IS_ALLOCATED  = 18;
	transient public static int RST_IS_RUNNING    = 20;
	transient public static int RST_IS_IN_PROCESS = 25;
	transient public static int RST_IS_COMPLETING = 50;
	transient public static int RST_IS_CLOSED     = 99;
	
	// object references ..............

	transient DataConnector dataConnector;
	transient MessageBoardFactory msgboardFactory ;
	transient ReceptorDigestIntf resultsReceiver;
	
	
	
	// main variables / properties ....s

	int receptorConnexID = -1;
	
	long instanceID = -1;
	
	String role = "" ;
	String nameOfApplicant = ""; // contains sth. like a GUID, provided by the MessageBoard !!!
	
	boolean instanceIsUnique = false ;
	
	double connectionDelay = -1.0 ;
	
	/** if true, then transaction data are saved by participants (S and R) and Message Board */
	boolean transactionPersistence = true;
	String suffixUID = "" ; // for unique instances, this is == "", for volatile instances >""
	                        // do not mix it with "nameOfApplicant", they are different !!
	                        // suffixUID is local, and used for hibernation, independent from the MessageBoard
	
	/** 
	 * meaning of values:<br/> 
	 * 1=active, 2=for http-rest, 3=completely passive for ftp (and tcp,udp for firewalls)<br/>
	 * the clients have to adjust their behavior accordingly to the mode of the board 
	 */
	int boardSendMode = 1 ; 
	boolean virtualPorts = false ; // the restlet mode handles this transparently on its own!
	int msgPortAllInOne = -1;
	
	int protocolID = -1;
	int port = 0;
	int activeport = 0;
	int clientListeningPort = 0;
	String hostname = "localhost" ;
	
	/** sth like "table", "doc", "document", "rawdata" "*" or any other string */
	String acceptType = ""; 
	int alignedResults = MessageBoardFactoryProperties.__ALIGNEDRESULTS_ASAP ;
	int alignedResultsBasketSize = -1;
	
	
	/** server-side flag for confirmed connection */ 
	boolean instanceTested = false;
	/** corresponding client-side flag for confirmed connection */ 
	boolean instanceConnectionConfirmed = false ;
	
	int receptorState = RST_IS_NOREGIST ;
	int connectionState = 0;
	
	boolean currentlySending = false;
	boolean currentlyWaitingforTID=false;
	
	long registeredSince = 0; // time in millis
	long timetolive = 0;
	transient long lastCheckTime = 0;
	 
	
	transient int openRequestsForTransaction=0;
	transient Vector<Long> alignmentQueue = new Vector<Long>();
	transient Vector<Long> tasksBeingCanceled = new Vector<Long>();
	/**
	 * link relation between sources and receptors
	 * 
	 * odd  1,3,5 -> a result may or may not be returned, dependent on the request of the SOURCE
	 * even 2,4,6 -> a result will definitely be returned in a given transaction 
	 * 
	 * note
	 */
	int srlinkRelation = -1;       
	int srRelationItemID = -1 ; 
	int srRelationGroupID = -1;					
	
	// constants ......................
	
	

	// volatile variables .............

	
	
	// helper objects .................
	
	transient XMessage xmsg ;
	transient PrintLog out;
	
	// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
	public XRegistration( ){
	}
	
	public void setOutPrn( PrintLog outprn ){
		out = outprn;
		xmsg=new XMessage(out);		
	}
	// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

	

	public void init( MessageBoardFactory mbf , ReceptorDigestIntf resultsreceiver){
		
		msgboardFactory = mbf ;
		resultsReceiver = resultsreceiver;
		
		dataConnector = new DataConnector( mbf, this , resultsReceiver);
		dataConnector.setNameOfInstance( getNameOfApplicant() ) ;
		
		if (role.contains("RECEPTOR")){
			receptorState = RST_IS_IDLE;
		}
	}
	
	public void close(){
		resultsReceiver = null;
		dataConnector.close() ;
		dataConnector = null;
	}
	
	
	public int cancelTask( long transactionID ){
		
		tasksBeingCanceled.add(transactionID) ;
		
		dataConnector.transmitCancelCommand(transactionID) ;
		// elsewhere : wait for confirmation
		// check connection
		return 0;
	}
	
	public void cancelAll(){

		dataConnector.transmitCancelCommand(0) ; // 0 causes a cancel all message !
		// elsewhere : wait for confirmation
		// check connection
		
		return ;
		
	}
	 
	public void send( String xmlout, int routableHops, Observer obs){
		
		// if routableHops>0 we have to introduces / change the respective entry in the XML
		// if the limit is reached, no further MessageBoard will be contacted with this message
		
		// dataConnector.setDedicatedObserver(obs);
		// this uses /data + "Post"
		dataConnector.transmitRequestToBoard( xmlout );
	}
	
	public void send(TaskPackage taskPackage, FilterPackageIntf filter, int routableHops){
		
		String uuid; 
		
		currentlySending = true ;
		currentlyWaitingforTID = true;
		
		if (dataConnector==null){
			// dataConnector
			if (out!=null)out.print(2, "DataConnector not available for instance ("+ getRole()+") "+ getInstanceID() );
			return ;
		}
		
		dataConnector.setFilterReference( filter, msgboardFactory.getFilterActivation() );
		
		uuid = dataConnector.taskForRelay(taskPackage) ;  
		
		dataConnector.setContentType( taskPackage.getContentType() ) ;
		 
		dataConnector.transmitSourceData(uuid) ;
		
		msgboardFactory.saveOpenTransactions(); 
		
		currentlySending = false;
		
		openRequestsForTransaction++;
	}
	
	public void send(TaskPackage taskPackage){
		FilterPackageIntf filter = null;
		
		send (taskPackage, filter,0) ; // no adhoc filter will be transferred
	}
	
	public void sendRequestPackage( String rawXmlMsg){
 
		dataConnector.transmitRequestToBoard( rawXmlMsg );

	}
	
	public void sendEchoResponse( String name, String xmlstr ){
		/*
		String str;
		str = nameOfApplicant ;
		
		
		str = xmsg.getSpecifiedInfo(xmlstr, "check", "id");
		// <check id="4ca80920-f357-11e0-96c4-e0f847024516"
		*/
		dataConnector.sendEchoResponse( this, name, xmlstr);
	}
	
	
	public void sendKeepAlive(){
		String xmlstr;
		
		xmlstr = xmsg.createConnectionCheckMsg(instanceID, nameOfApplicant , getRole(),2 ) ;
		// creates a "ping" of type "keepalive" which does NOT trigger 
		// a response / check by the connection manager...  it is upstream , hence no check
		
		dataConnector.simpleSend(xmlstr,0) ;
		
	}
	
	public void sendKeepAliveForTranaction( long transactionID ){
		
	}
	
	public void directSend( String xmlstr ){
	
		directSend( xmlstr,null);
	}
	
	public void directSend( String xmlstr, Observer dedicatedObserver ){ 
		
		// dedicatedObserver will bypass DataConnector, which is the default observer for send events...
		dataConnector.directSend( xmlstr, dedicatedObserver ) ;
	}
	

	
	public void retrieveAll( String contentType){
		String xmlstr , fullname ;
		long iid ;
		
		
		iid = this.getInstanceID() ;
		fullname = this.nameOfApplicant;

		xmlstr = xmsg.createRequestForRetrieveBulk(  iid, fullname ,contentType);
		/*
		 *   we will receive a list with all transaction IDs ready for delivered, but not 
		 *   retrieved so far
		 *   
		 *   this list we then use here to issue the standard retrieval procedure
		 *   
		 *   in "SourceBoardRepliesInterpreter{}" we have the method 
		 *   "handling_requestedTransactionList()" which translates the returned list into a task
		 *   that is further routed through callback to MessageReceptorDigester which implements ReceptorDigestIntf
		 *   
		 */
		dataConnector.simpleSend(xmlstr, 1);
		
	}
	
	
	public void sendConfirmationToBoard( Transaction transaction, int stateValue) {
		
		long instanceID=0, transactID=0;
		String secret="" ;
		
		if (dataConnector==null){
			// dataConnector
			if (out!=null)out.printErr(1, "DataConnector not available for instance ("+ getRole()+") "+ getInstanceID() );
			
			return ;
		}		
		
		transactID = transaction.getTransactionID() ;
		instanceID = transaction.getInstanceID() ;
		
		dataConnector.transmitReceptorResponse(instanceID, transactID, getRole(),stateValue,  secret,1); // 1 = confirm, 2=notific 3=simple state
		
	}
	
	
	public void sendStateToMsgBoard( long instanceID, long transactID, String role, int stateValue, String description ) {
	 
		
		if (dataConnector==null){
			// dataConnector
			if (out!=null)out.print(2, "DataConnector not available for instance ("+ getRole()+") "+ getInstanceID() );
			
			return ;
		}
		
		if (stateValue==Transaction.TS_TASK_ACCEPTED){
			 connectionState = DataConnector.CNX_AVAIL;
			 
		}
		if (stateValue==Transaction.TS_TASK_DENIED){
			connectionState = DataConnector.CNX_BUSY;
		}
		 
		// this will call "XMEssage.createReceptorStateMsg()"
		dataConnector.transmitReceptorResponse( instanceID, transactID, stateValue, description);
		 
	}
	
	public void sendResultReturn( long transactID, TaskPackage resultPackage ){
		String xml="";
		
		
		if (dataConnector==null){
			// dataConnector
			if (out!=null)out.print(2, "DataConnector not available for instance ("+ getRole()+") "+ getInstanceID() );
			return ;
		}
		
		// this.clientListeningPort ;
		// this.getInstanceID() ;
		// the observer is pointing to MessageRecceptor ? 
		xml = dataConnector.getSentXML();
		dataConnector.transmitReceptorResponse( transactID, resultPackage );
		
												out.print(2, "\nsendResultReturn(), Data (tid:"+transactID+") sent by RECEPTOR ...  ");
												out.print(5,xml );
		
		connectionState = DataConnector.CNX_AVAIL ;
		 
	}
	
	/**
	 * 
	 * this is the entry point for implementing the custom FilterPackage into the MessageBoard;
	 * the filter object will be serialized encoded and transmitted
	 *  
	 * @param filter
	 */
	public void announceFilter( FilterPackageIntf filter){
		// this filter will be transferred together with each taskpackage, if 
		// - no particular adhoc filter has been defined
		// - it is activated
		dataConnector.setFilterReference( filter, msgboardFactory.getFilterActivation() );

	}
	
	public int announceSubscription(String xmlstr){
		int result=-1;
		
		if (xmlstr.length()>20){
			result = 0;
			dataConnector.simpleSend(xmlstr,0) ;
		}
		return result ;
	}
	
	public void takeTransactionToAlignment( long transactionID ) {
		
		if (alignmentQueue.indexOf(transactionID)<0){
			alignmentQueue.add( transactionID );
		}
	}
	
	/**
	 * if results should be aligned, we have to care about the queue 
	 * if we have sent the results !
	 * 
	 * @param transactionID
	 */
	public void removeTransactionToAlignment( long transactionID ) {
		
		int ix;
		ix = alignmentQueue.indexOf(transactionID );
		if (ix>=0){
			alignmentQueue.remove( ix );
		}
	}

	public boolean transactionIsInLine(  long transactionID ){
		boolean rB = true;
		int ix;
		
		if ( ( receptorState <= RST_IS_NOREGIST ) || 
			 ( receptorState == RST_IS_CLOSED) ){
			return false;
		} 
			
		/* now we check if there is a disorder !
		   queue might be with gaps   10 11 12 17 21 25 45 46 47 51 52 56 57
		         available results   ...
		         since we remove a tid on sending, the perfect order is fulfilled exactly if the  
		         next transactionID is on the first place.
		         
		         for semi orders, the position should not exceed group size
		         
		         -> we do not need a loop, if we do not work with explicit milestones
		*/ 
		// for (int i=0;i<alignmentQueue.size();i++){ } // i->

		if ( alignedResults == MessageBoardFactoryProperties.__ALIGNEDRESULTS_ASAP){
			rB = true;
		}
		
		ix = alignmentQueue.indexOf(transactionID );
		
		if ( alignedResults == MessageBoardFactoryProperties.__ALIGNEDRESULTS_FULL){
			if (ix>0){
				rB = false;
			}
		}
		if ( alignedResults == MessageBoardFactoryProperties.__ALIGNEDRESULTS_SEMI){
			if ((ix<0) || (ix>=alignedResultsBasketSize)){
				rB = false;
			}
		}
		
		return rB;
	}
	
	
	public void unregister(){
		
		dataConnector.unregisterInstanceFromMessageBoard( this );
		
		this.resultsReceiver = null;
	}
	
	public void startWiredServer(){
		
		dataConnector.startWiredServer(clientListeningPort);
	}
	
	// ------------------------------------------------------------------------
	
	public static long getSerialversionuid() {
		return serialVersionUID;
	}


	static public XRegistration getItemByID( long id, Vector<XRegistration> registeredInstances){
		XRegistration xreg = null;
		
		for (int i=0;i<registeredInstances.size();i++){
			if (registeredInstances.get(i).getInstanceID() == id){
				xreg = registeredInstances.get(i) ;
				break;
			}
		}
		return xreg ;
	}


	static public XRegistration getItemByName( String xname, Vector<XRegistration> registeredInstances){
		XRegistration xreg = null;
		String regname ;
		
		for (int i=0;i<registeredInstances.size();i++){
			regname = registeredInstances.get(i).getNameOfApplicant();
			if ( regname.contentEquals( xname)){
				xreg = registeredInstances.get(i) ;
				break;
			}
		}
		return xreg ;
	}


	/**
	 * 
	 * @param providedDocTypes
	 * @param requestedDoctypes : * are not tested
	 * 
	 * @return
	 */
	static public boolean docTypeMatches( String providedDocTypes, String requestedDoctypes ){
		boolean rB = false;
		String[] ptypes, qtypes;
		String str ;
		
		
		
		requestedDoctypes = requestedDoctypes.replace("*", " ").trim() ;
		
		ptypes = providedDocTypes.split(",");
		qtypes = requestedDoctypes.split(",");
		
		for (int p=0;p<ptypes.length;p++){
			str = ptypes[p] ;
		
			for (int q=0;q<qtypes.length;q++){
				
				if (str.contentEquals(qtypes[q])){
					rB=true;
					break;
				}
			} // q ->	
		} // p ->
		
		return rB;
	}
	
	static public String decodeConnexStateValue( int stateValue){
		String wordedCode="" ;
		

	    switch (stateValue) {
	  
	    case -95 :
	    	wordedCode="RST_IS_TIMEDOUT"; break; 
	    case -7 :
	    	wordedCode="RST_CTYPEUNDEF"; break; 
	    case -6 :
	    	wordedCode="RST_CTYPENOMATCH"; break; 
	    case -1 :
	    	wordedCode="RST_IS_NOREGIST"; break; 
	    case 0 :
	    	wordedCode="RST_IS_STARTED"; break;
	    case 1 :
	    	wordedCode="RST_IS_CNXCONF"; break;
	    case 8 :
	    	wordedCode="RST_IS_IDLE"; break;
	    case 10 :
	    	wordedCode="RST_IS_AVAIL"; break;
	    case 15 :
	    	wordedCode="RST_IS_RECOGNIZED"; break;
	    case 18 :
	    	wordedCode="RST_IS_ALLOCATED"; break;
	    case 20 :
	    	wordedCode="RST_IS_RUNNING"; break;
	    case 25 :
	    	wordedCode="RST_IS_IN_PROCESS"; break;
	    case 50 :
	    	wordedCode="RST_IS_COMPLETING"; break;
	    case 99 :
	    	wordedCode="RST_IS_CLOSED"; break;
	    }
	    
		return wordedCode;
	}
	
	public long getInstanceID() {
		return instanceID;
	}



	public void setInstanceID(long instanceID) {
		this.instanceID = instanceID;
	}



	public int getReceptorConnexID() {
		return receptorConnexID;
	}



	public void setReceptorConnexID(int receptorConnexID) {
		this.receptorConnexID = receptorConnexID;
	}



	public String getNameOfApplicant() {
		return nameOfApplicant;
	}



	public void setNameOfApplicant(String nameOfApplicant) {
		this.nameOfApplicant = nameOfApplicant;
	}



	public String getSuffixUID() {
		return suffixUID;
	}


	public void setSuffixUID(String suffixUID) {
		this.suffixUID = suffixUID;
	}


	public String getRole() {
		return role;
	}



	public void setRole(String role) {
		this.role = role;
	}



	public DataConnector getDataConnector() {
		return dataConnector;
	}


	public MessageBoardFactory getMsgboardFactory() {
		return msgboardFactory;
	}


	public boolean isTransactionPersistence() {
		return transactionPersistence;
	}


	public void setTransactionPersistence(boolean transactionPersistence) {
		this.transactionPersistence = transactionPersistence;
	}

 

	/**
	 * getting {@link boardSendMode}, see {@link setBoardSendMode} 
	 * @return
	 */
	public int getBoardSendMode() {
		return boardSendMode;
	}

	/**
	 * defining {@link boardSendMode}<br/>
	 * 
	 * meaning of values:<br/> 
	 * 1=active, 2=for http-rest, 3=completely passive for ftp (and tcp,udp for firewalls)<br/>
	 * the clients have to adjust their behavior accordingly to the mode of the board 
	 
	 * @param boardSendMode
	 */
	public void setBoardSendMode(int boardSendMode) {
		this.boardSendMode = boardSendMode;
	}


	public boolean isVirtualPorts() {
		return virtualPorts;
	}


	public void setVirtualPorts(boolean virtualPorts) {
		this.virtualPorts = virtualPorts;
	}


	public int getMsgPortAllInOne() {
		return msgPortAllInOne;
	}


	public void setMsgPortAllInOne(int msgPortAllInOne) {
		this.msgPortAllInOne = msgPortAllInOne;
	}


	public int getPort() {
		return port;
	}



	public void setPort(int port) {
		this.port = port;
	}



	public int getActiveport() {
		return activeport;
	}



	public void setActiveport(int activeport) {
		this.activeport = activeport;
	}



	public int getClientListeningPort() {
		return clientListeningPort;
	}



	public void setClientListeningPort(int clientListeningPort) {
		this.clientListeningPort = clientListeningPort;
	}



	public int getProtocolID() {
		return protocolID;
	}

	public void setProtocolID(int protocolID) {
		this.protocolID = protocolID;
	}

	public String getHostname() {
		return hostname;
	}


	public void setHostname(String hostname) {
		this.hostname = hostname;
	}


	public double getConnectionDelay() {
		return connectionDelay;
	}


	public void setConnectionDelay(double connectionDelay) {
		this.connectionDelay = connectionDelay;
	}


	public int getConnectionState() {
		return connectionState;
	}


	public void setConnectionState(int connectionstate) {
		
		 	
			if (connectionstate<0){
				connectionstate = DataConnector.CNX_AVAIL;
			}
			if ((connectionstate>DataConnector.CNX_AVAIL) && (connectionstate<DataConnector.CNX_BUSY)){
				connectionstate = DataConnector.CNX_BUSY ;
			}
			if ( ((connectionstate>DataConnector.CNX_BUSY) && (connectionstate<DataConnector.CNX_OFF)) || 
				 (connectionstate>DataConnector.CNX_OFF)){
				connectionstate = DataConnector.CNX_OFF ;
			}
		 
		connectionState = connectionstate;
	}


	public boolean isInstanceIsUnique() {
		return instanceIsUnique;
	}
	public boolean getInstanceIsUnique() {
		return instanceIsUnique;
	}


	public void setInstanceIsUnique(boolean instanceIsUnique) {
		this.instanceIsUnique = instanceIsUnique;
	}


	public String getAcceptType() {
		return acceptType;
	}



	public void setAcceptType(String acceptType) {
		this.acceptType = acceptType;
	}

	public int getAlignedResults() {
		return alignedResults;
	}

	public void setAlignedResults(int alignedResults) {
		this.alignedResults = alignedResults;
	}

	public int getAlignedResultsBasketSize() {
		return alignedResultsBasketSize;
	}

	public void setAlignedResultsBasketSize(int alignedResultsBasketSize) {
		this.alignedResultsBasketSize = alignedResultsBasketSize;
		
		if (alignedResultsBasketSize<=0){
			alignedResults = MessageBoardFactoryProperties.__ALIGNEDRESULTS_ASAP ;	
		}
		if (alignedResultsBasketSize==1){
			alignedResults = MessageBoardFactoryProperties.__ALIGNEDRESULTS_FULL ;	
		}
		if (alignedResultsBasketSize>1){
			alignedResults = MessageBoardFactoryProperties.__ALIGNEDRESULTS_SEMI ;	
		}
		
	}

	public Vector<Long> getAlignmentQueue() {
		return alignmentQueue;
	}

	public Vector<Long> getTasksBeingCanceled() {
		return tasksBeingCanceled;
	}

	public int getReceptorState() {
		return receptorState;
	}


	public void setReceptorState(int receptorState) {
		this.receptorState = receptorState;
	}


	public boolean isCurrentlySending() {
		return currentlySending;
	}
	public int getOpenRequestsForTransaction() {
		return openRequestsForTransaction;
	}

	public void setOpenRequestsForTransaction(int openRequestsForTransaction) {
		this.openRequestsForTransaction = openRequestsForTransaction;
		if (openRequestsForTransaction<0){
			openRequestsForTransaction=0;
		}
	}

	public boolean getCurrentlyWaitingforTID(){
		return currentlyWaitingforTID;
	}
	
	public void setCurrentlyWaitingforTID( boolean flag){
		currentlyWaitingforTID = flag;
	}

	public boolean getCurrentlySending() {
		return currentlySending;
	}


	public void setCurrentlySending(boolean currentlySending) {
		this.currentlySending = currentlySending;
	}


	public long getRegisteredSince() {
		return registeredSince;
	}


	public void setRegisteredSince(long registeredSince) {
		this.registeredSince = registeredSince;
	}


	public long getTimetolive() {
		return timetolive;
	}

	public void setTimetolive(long timetolive) {
		this.timetolive = timetolive;
	}

	public long getLastCheckTime() {
		return lastCheckTime;
	}


	public void setLastCheckTime(long lastCheckTime) {
		this.lastCheckTime = lastCheckTime;
	}


	public boolean isInstanceTested() {
		return instanceTested;
	}


	public void setInstanceTested(boolean instanceTested) {
		this.instanceTested = instanceTested;
		if (instanceTested){
			connectionState = RST_IS_CNXCONF;
		}else{
			connectionState = RST_IS_STARTED ;
		}
	}


	public boolean isInstanceConnectionConfirmed() {
		return instanceConnectionConfirmed;
	}


	public boolean getInstanceConnectionConfirmed(){
		return instanceConnectionConfirmed;
	}
	
	public void setInstanceConnectionConfirmed(boolean connectionConfirmed) {
	
		instanceConnectionConfirmed = connectionConfirmed;
		
		if (receptorState<RST_IS_CNXCONF){
			receptorState = RST_IS_CNXCONF;
		}
		connectionState = RST_IS_CNXCONF;
	}


	public int getSrlinkRelation() {
		return srlinkRelation;
	}


	public void setSrlinkRelation(int srlinkRelation) {
		this.srlinkRelation = srlinkRelation;
	}


	public int getSrRelationItemID() {
		return srRelationItemID;
	}


	public void setSrRelationItemID(int srRelationItemID) {
		this.srRelationItemID = srRelationItemID;
	}


	public int getSrRelationGroupID() {
		return srRelationGroupID;
	}


	public void setSrRelationGroupID(int srRelationGroupID) {
		this.srRelationGroupID = srRelationGroupID;
	}



	 
	
	
}
